import { useEffect } from "react";
import router from "./router";
import { useLocation, useNavigate, useRoutes } from "react-router-dom";
import { message } from "antd";

function ToLogin() {
  const navigateTo = useNavigate();
  useEffect(() => {
    navigateTo("/login");
    message.warning("您还没有登录，请登录后再访问!");
  }, [navigateTo]);
  return <div></div>;
}
function ToHome() {
  const navigateTo = useNavigate();
  useEffect(() => {
    navigateTo("/home");
    message.warning("您已经登录过了!");
  }, [navigateTo]);
  return <div></div>;
}

function BeforeRouterEnter() {
  const outlet = useRoutes(router);
  // const localtion = useLocation();
  // const token: any = localStorage.getItem("token");
  // if (localtion.pathname === "/login" && token) {
  //   return <ToHome />;
  // }
  // if (localtion.pathname !== "/login" && !token) {
  //   return <ToLogin />;
  // }
  return outlet;
}

function App() {
  return (
    <>
      {/* <NavLink to="/home">Home</NavLink>
      <NavLink to="/about">About</NavLink>
      <NavLink to="/user">User</NavLink> */}

      {/* 占位符组件 */}
      {/* {outlet} */}
      <BeforeRouterEnter />
    </>
  );
}

export default App;
